<?php

namespace App\Http\Controllers;

use App\Http\Classes\Excel\InputExcel;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redis;

class ExcelController extends Controller
{
    //
    public function showpage()
    {
        return view('downpage');
    }

    public function getExcel()
    {
        $data = DB::select('select `province_name`,`city_name`,`county_name`,`town_name`,`village_name` from jquanguo where id<11');
        $obj = new InputExcel();
        $filename = Input::get('filename');
//        dd($filename);
        $rs = $obj->inputexcel($filename,$data);
//,'name'=>$filename
        return response()->json(['status'=>'0','msg'=>'响应成功','name'=>"$filename"]);
    }

    public function downExcelfile()
    {
        $filename = substr($_SERVER["REQUEST_URI"],strrpos($_SERVER["REQUEST_URI"],'/')+1);
        $path = './module/jifenbao/onload/'.$filename.'.xlsx';
        return response()->download($path);

        /*header("Content-type: application/octet-stream");
        header("Accept-Ranges: bytes");
        header("Accept-Length: ".filesize($path));
        header("Content-Disposition: attachment; filename=" . $filename);
        while(!feof($file)){
            echo fread($file,2048);
        }
        fclose($file);
        @unlink($path);
        exit();*/

    }

    private function _downExcelfile($path)
    {
        return response()->download($path);
    }

    public function getRedis(){
        Redis::set('newkey','value');
//        Cache::store('redis')->put('jian','jianvalue',1);
//        Cache::put('jian','jianvalue',1);
        var_dump( Cache::get('jian') );
//        echo Redis::get('newkey');
    }

}
